﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Threading;
using System.Windows.Threading;

namespace TimeRuler
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();
            //读取文件，初始化全局totalTime
            if (File.Exists(ProgramFile.time))
            {
                if (Time.TotalTime == 0)
                    Time.TotalTime = Convert.ToInt32(File.ReadAllText(ProgramFile.time));
            }
            else
                Directory.CreateDirectory(ProgramFile.baseDictionary);

            RefreshWindow();
        }
        private int goalTime = 60;
        private int goalNumber = 0;

        private void addTimeButton_Click(object sender, RoutedEventArgs e)
        {
            Time.TotalTime += Convert.ToInt32(addTimeBox.Text) * 60;
            RefreshWindow();
        }
        private void RefreshWindow()
        {
            //总计标签
            timeLabel.Content = TimeConvert.DescribeTime(Time.TotalTime, "总计");
            while (Time.TotalTime >= goalTime)
            {
                goalTime *= 5;
                goalNumber++;
            }
            goalLabel.Content = TimeConvert.DescribeTime(goalTime, "目标");
            goalNumberLabel.Content = $"已完成目标：{goalNumber}个";
            timeProgress.Value = Convert.ToDouble(Time.TotalTime) /
               Convert.ToDouble(goalTime) * 100;
            File.WriteAllText(ProgramFile.time, Time.TotalTime.ToString());

        }

        private void timerButton_Click(object sender, RoutedEventArgs e)
        {
            TimerRunner timerRunner = new();
            NavigationService.Navigate(timerRunner);
        }
    }
}